package cn.zldemo;

import android.app.ActivityOptions;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import cn.zldemo.util.ViewMapping;
import cn.zldemo.util.ViewMappingUtil;

@ViewMapping(id = R.layout.activity_main)
public class MainActivity extends AppCompatActivity {
	@ViewMapping(id = R.id.txt)
	private TextView textView;
	@ViewMapping(id = R.id.frame)
	private View frame;
	@ViewMapping(id = R.id.flip)
	private Button flip;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS);
		// getWindow().setEnterTransition(new Explode());
		// getWindow().setExitTransition(new Explode());
		super.onCreate(savedInstanceState);
		ViewMappingUtil.mapView(this, this);

		textView.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				Intent intent = new Intent(MainActivity.this, MainActivity2Activity.class);
				ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(MainActivity.this, textView,
						"text1");
				startActivity(intent, options.toBundle());
			}
		});

		flip.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				startActivity(new Intent(MainActivity.this, FlipperActivity.class));
			}
		});
		// textView.setOnClickListener(new View.OnClickListener() {
		// @Override
		// public void onClick(View v) {
		// Animation animation =
		// AnimationUtils.makeOutAnimation(MainActivity.this, true);
		// animation.setInterpolator(PathInterpolatorCompat.create(25.0f, 400f,
		// 700.0f, 480.5f));
		// v.startAnimation(animation);
		// }
		// });

		// frame.setOnTouchListener(new View.OnTouchListener() {
		// @Override
		// public boolean onTouch(View v, MotionEvent event) {
		// if (event.getAction() == MotionEvent.ACTION_DOWN) {
		// int cx = (int) event.getX(), cy = (int) event.getY();
		// ViewAnimationUtils.createCircularReveal(v, cx, cy,
		// Math.max(v.getWidth(), v.getHeight()), 0)
		// .start();
		// return true;
		// }
		// return false;
		// }
		// });
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.menu_main, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle action bar item clicks here. The action bar will
		// automatically handle clicks on the Home/Up button, so long
		// as you specify a parent activity in AndroidManifest.xml.
		int id = item.getItemId();

		// noinspection SimplifiableIfStatement
		if (id == R.id.action_settings) {
			return true;
		}

		return super.onOptionsItemSelected(item);
	}
}
